package com.leilbase.mspring.starter;

import com.leilbase.mspring.bean.BeanFactory;
import com.leilbase.mspring.core.ClassScanner;
import com.leilbase.mspring.web.handler.MappingHandlerManager;
import com.leilbase.mspring.web.server.TomcatServer;
import org.apache.catalina.LifecycleException;

import java.io.IOException;
import java.util.List;

public class MiniApplication {

    public static void run(Class<?> cls, String[] args) {
        TomcatServer tomcatServer = new TomcatServer(args);
        try {
            tomcatServer.startServer();
            List<Class<?>> classList = ClassScanner.scanClass(cls.getPackage().getName());
            BeanFactory.initBeans(classList);
            MappingHandlerManager.resolveMappingHandler(classList);
        } catch (Exception e) {
            e.printStackTrace();
        }

//        try {
//            String packageName = cls.getPackage().getName();
//            List<Class<?>> classList = ClassScanner.scanClass(cls.getPackage().getName());
//            classList.forEach(it->System.out.println(it.getName()));
//        } catch (IOException e) {
//            e.printStackTrace();
//        } catch (ClassNotFoundException e) {
//            e.printStackTrace();
//        }
    }


}
